package com.example.lenovo.wechattest;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class SessionAdapter extends RecyclerView.Adapter {
    public List<Sessions> mSessions;

    public SessionAdapter(List<Sessions> sessions) {
        mSessions = sessions;
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.wechat_sessions, viewGroup, false);
        return new RecyclerView.ViewHolder(view) {};
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        ImageView ivAvatar = viewHolder.itemView.findViewById(R.id.iv_wechat_avatars);
        TextView tvTitle = viewHolder.itemView.findViewById(R.id.tv_wechat_title);

        ivAvatar.setImageResource(mSessions.get(i).avatar);
        tvTitle.setText(mSessions.get(i).title);
    }

    @Override
    public int getItemCount() {
        return mSessions.size();
    }
}
